package com.property.manage.controller.rent;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.equipment.EquipmentVo;
import com.property.manage.model.rent.RentVo;
import com.property.manage.model.system.SysSet;
import com.property.manage.service.equipment.EquipmentService;
import com.property.manage.service.rent.RentService;
import com.property.manage.service.system.SysSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "租金管理")
@RestController
@RequestMapping("/rent")
@AllArgsConstructor
@Validated
public class RentController {
    @Autowired
    private RentService rentService;

    @ApiOperation("租金列表")
    @GetMapping("/page")
    public CustomPage<RentVo> getPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                       @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                       @ApiParam("租金类型") @RequestParam(value = "type", required = false) Integer type,
                                       @ApiParam("小区id") @RequestParam(value = "villageId", required = false) Integer villageId,
                                       @ApiParam("租户") @RequestParam(value = "name", required = false) String name){
        return rentService.page(pageNo,pageSize,type,villageId,name);
    }

    @ApiOperation("添加租金")
    @PostMapping("/add")
    public void add(@ApiParam("小区id")@RequestParam(value = "villageId")@NotNull(message = "小区id不能为空") Integer villageId,
                    @ApiParam("租户名称")@RequestParam(value = "name")@NotBlank(message = "租户名称") String name,
                    @ApiParam("房屋地址/车位编号") @RequestParam(value = "number",required = false) String number,
                    @ApiParam("联系方式")@RequestParam(value = "phone") String phone,
                    @ApiParam("下次缴费")@RequestParam(value = "nextTime",required = false) LocalDate nextTime,
                    @ApiParam("开始时间")@RequestParam(value = "startTime")@NotNull(message = "开始时间") LocalDate startTime,
                    @ApiParam("结束时间")@RequestParam(value = "endTime")@NotNull(message = "结束时间") LocalDate endTime,
                    @ApiParam("租金金额")@RequestParam(value = "money")@NotNull(message = "租金不能为空")BigDecimal money,
                    @ApiParam("租金类型 2 房屋租金 3车位租金")@RequestParam(value = "type")@NotNull(message = "类型不能为空")Integer type,
                    @ApiParam("楼栋id")@RequestParam(value = "buildingId",required = false)Integer buildingId
    ){
        rentService.add(money,nextTime,startTime,endTime,name,phone,type,number,buildingId,villageId);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,
                       @ApiParam("租户名称")@RequestParam(value = "name")@NotBlank(message = "租户名称") String name,
                       @ApiParam("房屋地址/车位编号") @RequestParam(value = "number",required = false) String number,
                       @ApiParam("联系方式")@RequestParam(value = "phone") String phone,
                       @ApiParam("下次缴费")@RequestParam(value = "nextTime",required = false) LocalDate nextTime,
                       @ApiParam("开始时间")@RequestParam(value = "startTime")@NotNull(message = "开始时间") LocalDate startTime,
                       @ApiParam("结束时间")@RequestParam(value = "endTime")@NotNull(message = "结束时间") LocalDate endTime,
                       @ApiParam("租金金额")@RequestParam(value = "money")@NotNull(message = "租金不能为空")BigDecimal money,
                       @ApiParam("租金类型 2 房屋租金 3车位租金")@RequestParam(value = "type")@NotNull(message = "类型不能为空")Integer type,
                       @ApiParam("楼栋id")@RequestParam(value = "buildingId",required = false)Integer buildingId,
                       @ApiParam("小区id")@RequestParam(value = "villageId")@NotNull(message = "小区id不能为空") Integer villageId
    ){
      rentService.update(id,money,nextTime,startTime,endTime,name,phone,type,number,buildingId,villageId);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("id") @RequestParam("id") @NotNull(message = "id为空") Integer id){
        rentService.delete(id);
    }


}
